package com.soujiayi.store;

import java.util.Map;
import android.content.Context;
import android.content.SharedPreferences;

public class SPResolver {
	SharedPreferences.Editor editor;
	Context context;
	SharedPreferences sp;

	public SPResolver(Context c, String name, int mode) {
		context = c;
		sp = context.getSharedPreferences(name, mode);
				
	}

	public final boolean contains(String key) {
		return sp.contains(key);
	}

	public final Map<String, ?> getAll() {
		return sp.getAll();
	}

	public final String getValue(String key, String defaultValue) {
		return sp.getString(key, defaultValue);
	}

	public final boolean getValue(String key, boolean defaultValue) {
		return sp.getBoolean(key, defaultValue);
	}

	public final float getValue(String key, float defaultValue) {
		return sp.getFloat(key, defaultValue);
	}

	public final int getValue(String key, int defaultValue) {
		return sp.getInt(key, defaultValue);
	}

	public final long getValue(String key, long defaultValue) {
		return sp.getLong(key, defaultValue);
	}

	public final void registerOnSharedPreferenceChangeListener(
			SharedPreferences.OnSharedPreferenceChangeListener listener) {
		sp.registerOnSharedPreferenceChangeListener(listener);
	}

	public final void unregisterOnSharedPreferenceChangeListener(
			SharedPreferences.OnSharedPreferenceChangeListener listener) {
		sp.unregisterOnSharedPreferenceChangeListener(listener);
	}

	public final void OpenEditor() {
		if (editor == null)
			editor = sp.edit();
	}

	public final void clearEditor() {
		editor.clear();
	}

	public final void putValue(String key, String value) {
		editor.putString(key, value);
	}

	public final void putValue(String key, boolean value) {
		editor.putBoolean(key, value);
	}

	public final void putValue(String key, float value) {
		editor.putFloat(key, value);
	}

	public final void putValue(String key, int value) {
		editor.putInt(key, value);
	}

	public final void putValue(String key, long value) {
		editor.putLong(key, value);
	}

	public final void remove(String key) {
		editor.remove(key);
	}

	public final void commitEditor() {
		if (editor != null)
			editor.commit();
	}

	public final void closeEditor() {
		editor = null;
	}
}